package com.example.springblog.moder;

import com.example.springblog.common.Constants;
import lombok.Data;

@Data
public class Result<T> {
    private Integer code;//200成功 -1失败
    private String errMsg;
    private T data;

    public static <T>Result<T> success(T data){
        Result result = new Result();
        result.setCode(Constants.SUCCESS);
        result.setErrMsg("");
        result.setData(data);
        return result;
    }

    public static <T>Result<T> fail(String errMsg){
        Result result = new Result();
        result.setCode(Constants.FAIL);
        result.setErrMsg(errMsg);
        return result;
    }

    public static <T>Result<T> fail(String errMsg, T data){
        Result result = new Result();
        result.setCode(Constants.FAIL);
        result.setErrMsg(errMsg);
        result.setData(data);
        return result;
    }

}
